﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Company_Default : System.Web.UI.Page
{
    public string CompanyName, keywords, p_title, lb_company;
    public string UserID, WebUrl, uID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            pro_fon();
        }
    }
    public void pro_fon()
    {
        int pid = int.Parse(Request.QueryString["p_id"]);
        int uid = int.Parse(Request.QueryString["p_UserID"]);

        //if (pid != null && uid != null)
        //{
            DataTable dt = Class1.ExecSel("select * from product where p_ID=" + pid + " and p_UserID=" + uid + "");

            if (dt.Rows[0]["p_ProImg"].ToString() != "" && dt.Rows[0]["p_ProImg"].ToString() != null)
            {
                lb_pro.Text = "<img src=../" + dt.Rows[0]["p_ProImg"].ToString() + " border=0 width=400 height=250/>";
            }
            lb_prices.Text = "￥"+dt.Rows[0]["p_Prices"].ToString()+".00";
            lb_Amount.Text = dt.Rows[0]["p_Amount"].ToString();
            lb_sm.Text = dt.Rows[0]["p_Prices"].ToString();
            lb_gg.Text = dt.Rows[0]["p_Specifications"].ToString();
            p_title = dt.Rows[0]["p_Title"].ToString();
            //lb_date.Text = DateTime.Parse(dt.Rows[0]["p_EndTime"].ToString()).ToShortDateString();

            int a = int.Parse(dt.Rows[0]["p_EndTime"].ToString());
            DateTime EndTime = DateTime.Now;
            EndTime = EndTime.AddDays(a);
            lb_date.Text = EndTime.ToString();

            lb_content.Text = dt.Rows[0]["p_Content"].ToString();
            CompanyName = Convert.ToString(dt.Rows[0]["p_CompanyName"].ToString());
            UserID = Convert.ToString(dt.Rows[0]["p_UserID"].ToString());

            DataTable dtk = Class1.ExecSel("select * from wj_User where wj_ID=" + uid + "");
            keywords = Convert.ToString(dtk.Rows[0]["wj_keywords"].ToString());
            WebUrl = Convert.ToString(dtk.Rows[0]["wj_WebUrl"].ToString());
            uID = dtk.Rows[0]["wj_ID"].ToString();
            lb_company = dtk.Rows[0]["wj_CompanyName"].ToString();
       // }
    }


    //TODO 添加购物车代码
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DateTime G_Time = DateTime.Now;
        int G_ID = int.Parse(Request.QueryString["p_ID"].Split(',')[0]);
        int uid = int.Parse(Request.QueryString["p_UserID"].Split(',')[0]);

        string SQL = "select * from product where p_ID=" + G_ID + " and p_UserID=" + uid + "";

        DataTable dt0 = Class1.ExecSel(SQL);
        string p_Title1 = dt0.Rows[0]["p_Title"].ToString();
        string Prices1 = dt0.Rows[0]["p_Prices"].ToString();
        string p_b = dt0.Rows[0]["p_b_ID"].ToString();
        string p_z = dt0.Rows[0]["p_z_ID"].ToString();
        DataTable dt1 = Class1.ExecSel("select  * from PsClass where  Menu_ID=" + p_b + "");
        DataTable dt2 = Class1.ExecSel("select  * from PsClass where  Menu_ID=" + p_z + "");
        string ppd = dt1.Rows[0]["Menu_Name"].ToString();
        string ppx = dt2.Rows[0]["Menu_Name"].ToString();

        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            string G_User = Session["wj_User"].ToString();
            string USQL = "select wj_User,wj_ID from wj_User where wj_User='" + G_User + "'";
            DataTable dt = Class1.ExecSel(USQL);

            string usql = "select count(*) from Cart where G_PID='" + G_ID + "' and G_UID='" + dt.Rows[0]["wj_ID"].ToString() + "'";
            int i = int.Parse(Class1.SelOne(usql));
            if (i == 0)
            {
                string GSql = "insert into Cart(G_UID,G_PID,G_D,G_X,G_TITLE,G_PRICES,G_TOTAL,G_Time)values('" + dt.Rows[0]["wj_ID"].ToString() + "','" + G_ID + "','" + ppd + "','" + ppx + "','" + p_Title1 + "','" + Prices1 + "','" + Prices1 + "','" + G_Time + "')";
                Class1.ExecSql(GSql);
                Response.Redirect("../wjCart.aspx");
            }
            else
            {
                string HSQL = ("update Cart set G_AMOUNT=G_AMOUNT+1 where G_PID=" + G_ID);
                Class1.ExecSql(HSQL);
                Response.Redirect("../wjCart.aspx");
            }

        }
    }
}
